package tieba.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tieba.dao.ICmsUserDAO;
import tieba.entity.CmsUser;
import tieba.service.ICmsUserService;

@Service("cmsUserService")
public class CmsUserService extends BaseService<CmsUser> implements
		ICmsUserService {

	private final ICmsUserDAO cmsUserDao;

	@Autowired
	public CmsUserService(ICmsUserDAO cmsUserDao) {
		super(cmsUserDao);
		this.cmsUserDao = cmsUserDao;
	}

	@Override
	public CmsUser login(CmsUser user) {
		Map<String, Object> conditions = new HashMap<>();
		conditions.put("username", user.getUsername());
		conditions.put("password", user.getPassword());
		return cmsUserDao.searchUnique(conditions, false);
	}

	@Override
	public boolean findByName(String name) {
		return cmsUserDao.selectByName("username", name);
	}
}
